/**
 * Created by jaliu on 2014/11/5.
 */

/**
 * 数据的初始化
 */
var async = require('async');
//var hobby = mongoose.model('masterData_Hobbies');

var bulletins = mongoose.model('community_bulletins');
var user = mongoose.model('user');
var community = mongoose.model('community');
var question = mongoose.model('question');
var banner = mongoose.model('system_BannerDefinitions');
var dataDictionary = mongoose.model('masterData_Dictionaries');


//初始化小区公告
bulletins.count(function (err, count) {
    if (count == 0) {
        async.series([
            function (callback) {
               /* 宝宝树66小区二次改造    mod   zhangm  20170723   start*/
                /*community.findOne({'communityName': '66小区'}, function (err, result) {*/
               community.findOne({'communityName': '宝宝树66小区'}, function (err, result) {
                    /*宝宝树66小区二次改造    mod   zhangm  20170723   end*/
                    var temp = new bulletins();
                    temp.community = result._id;
                    temp.displayOrder = 1;
                    temp.type = '物业';
                    temp.title = '关于变更24小时服务电话的温馨提示';
                    temp.content.desc = '因公司管理需要,即日起我管理处原24小时物业服务电话:0***-*******停止使用,同时启用新的24小时服务电话:0***-*******。如您需要帮助和服务请拨打更改后的电话号码,由此给您带来的不便敬请谅解!';
                    temp.createdBy = '548e63ef213a6cbc0c75f3a9';
                    temp.save(callback);
                })
            },
            function (result, callback) {
                /* 宝宝树66小区二次改造    mod   zhangm  20170723   start*/
                /*community.findOne({'communityName': '66小区'}, function (err, result) {*/
                community.findOne({'communityName': '宝宝树66小区'}, function (err, result) {
                    /* 宝宝树66小区二次改造    mod   zhangm  20170723   end*/
                    var temp = new bulletins();
                    temp.community = result._id;
                    temp.displayOrder = 2;
                    temp.type = '物业';
                    temp.title = '关于缴纳各项费用的通知';
                    temp.content.desc = '**年**月的公摊电费、二次供水水费已经核算完毕,请各位业主/住户在**月**日之前到管理处缴纳。同时现在开始收取**年**月—**年**月的物业管理费,请大家到管理处来缴纳。如您在此期间来管理处缴费用有困难,请务必和管理处联系协商解决,联系电话:*******。谢谢您的合作!';
                    temp.createdBy = '548e63ef213a6cbc0c75f3a9';
                    temp.save(callback);
                })
            }
        ]);
    }
});


/**
 * 初始化问题
 */
question.count(function (err, count) {
    if (count == 0) {
        async.series([
            function (callback) {
                /* 宝宝树66小区二次改造    mod   zhangm  20170723   start*/
                community.findOne({'communityName': '宝宝树66小区'}, function (err, comm) {
                        /*community.findOne({'communityName': '宝宝树66小区'}, function (err, comm) {*/
                    /* 宝宝树66小区二次改造    mod   zhangm  20170723   start*/
                    dataDictionary.findOne({'value': '宠物'}, function (err, dic) {
                        user.findOne({'nickName': '小区百晓生'}, function (err, user) {
                            var temp = new question();
                            temp.community = comm._id;
                            temp.category = 'question';
                            temp.tag = dic._id;
                            temp.status = '已解决';
                            temp.desc = '请问这是什么品种的犬';
                            temp.createdBy = user._id;
                            temp.save(callback);
                        })
                    })
                })
            },
            function (callback) {
                var images = [
                    {"imageURL": "/img/quan1.jpg"}, {"imageURL": "/img/quan2.jpg"}
                ];
                question.update({'desc': '请问这是什么品种的犬'}, {$pushAll: {'images': images}}).exec(callback);
            },
            function (callback) {
                user.findOne({'nickName': '小区百晓生'}, function (err, user) {
                    var replies = [{
                        "replyStatus": '已采纳',
                        "replyDesc": '估计是蝴蝶犬小串串吧~~花色什么的都很接近~~',
                        "repliedBy": user._id
                    }, {
                        "replyStatus": '未采纳',
                        "replyDesc": '串了好几代，算小形田园犬吧',
                        "repliedBy": user._id
                    }];
                    question.update({'desc': '请问这是什么品种的犬'}, {$pushAll: {'replies': replies}}).exec(callback);
                })
            }
        ])
    }
});

banner.count(function (err, count) {
    if (count == 0) {
        async.series([
            function (callback) {
                user.findOne({'nickName': '小区百晓生'}, function (err, user) {
                    var temp = new banner();
                    temp.stickyPage = 'questionHomePage';
                    temp.createdBy = user._id;
                    temp.save(callback);
                });

            },
            function (callback) {
                var banners = [{
                    "displayOrder": 1,
                    "desc": '没有任何门槛，不限任何才艺。达人秀的核心标志便是如此，让拥有才华和梦想的任何一个普通人，都可以参与到其中来展示其天赋和潜能。',
                    "backgroundImageURL": '/img/banner1.png'
                },
                    {
                        "displayOrder": 2,
                        "desc": '依稀记得那年隔壁阿姨偷偷塞给我的大白兔奶糖，而今那一扇扇门,仿佛也断了这记忆中的甜味。',
                        "backgroundImageURL": '/img/banner2.jpg'
                    },
                    {
                        "displayOrder": 3,
                        "desc": '当年的弄堂里有各式各样的牛人让你羡慕，一尺粗布亦能变幻万千,一曲亮嗓便折煞无数。',
                        "backgroundImageURL": '/img/banner3.jpg'
                    }]

                banner.update({}, {$pushAll: {'banner': banners}}).exec(callback);
            }
        ])
    }
});
